package com.cn.goodsadmin.common.frame;

import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLKeyException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLProtocolException;
import java.io.*;
import java.net.*;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileLockInterruptionException;
import java.nio.charset.MalformedInputException;
import java.nio.charset.UnmappableCharacterException;
import java.util.InvalidPropertiesFormatException;
import java.util.zip.ZipException;

public class NetTools {

	/**
	 * 细分ioexception的错误
	 * @param e
	 * @return
	 */
	public static int getErrorCodeFromException(IOException e) {
		if (e instanceof CharConversionException) {
			return NetWorkConstans.ERROR_IO_CharConversionException;
		} else if (e instanceof MalformedInputException) {
			return NetWorkConstans.ERROR_IO_CharacterCodingException_MalformedInputException;
		} else if (e instanceof UnmappableCharacterException) {
			return NetWorkConstans.ERROR_IO_CharacterCodingException_UnmappableCharacterException;
		}  else if (e instanceof ClosedChannelException) {
			return NetWorkConstans.ERROR_IO_ClosedChannelException;
		} else if (e instanceof EOFException) {
			return NetWorkConstans.ERROR_IO_EOFException;
		} else if (e instanceof FileLockInterruptionException) {
			return NetWorkConstans.ERROR_IO_FileLockInterruptionException;
		} else if (e instanceof FileNotFoundException) {
			return NetWorkConstans.ERROR_IO_FileNotFoundException;
		} else if (e instanceof HttpRetryException) {
			return NetWorkConstans.ERROR_IO_HttpRetryException;
		} else if (e instanceof SocketTimeoutException) {
			return NetWorkConstans.ERROR_IO_InterruptedIOException_SocketTimeoutException;
		} else if (e instanceof InvalidPropertiesFormatException) {
			return NetWorkConstans.ERROR_IO_InvalidPropertiesFormatException;
		}  else if (e instanceof MalformedURLException) {
			return NetWorkConstans.ERROR_IO_MalformedURLException;
		}  else if (e instanceof InvalidClassException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_InvalidClassException;
		} else if (e instanceof InvalidObjectException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_InvalidObjectException;
		} else if (e instanceof NotActiveException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_NotActiveException;
		} else if (e instanceof NotSerializableException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_NotSerializableException;
		} else if (e instanceof OptionalDataException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_OptionalDataException;
		} else if (e instanceof StreamCorruptedException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_StreamCorruptedException;
		} else if (e instanceof WriteAbortedException) {
			return NetWorkConstans.ERROR_IO_ObjectStreamException_WriteAbortedException;
		} else if (e instanceof ProtocolException) {
			return NetWorkConstans.ERROR_IO_ProtocolException;
		} else if (e instanceof SSLHandshakeException) {
			return NetWorkConstans.ERROR_IO_SSLException_SSLHandshakeException;
		} else if (e instanceof SSLKeyException) {
			return NetWorkConstans.ERROR_IO_SSLException_SSLKeyException;
		} else if (e instanceof SSLPeerUnverifiedException) {
			return NetWorkConstans.ERROR_IO_SSLException_SSLPeerUnverifiedException;
		} else if (e instanceof SSLProtocolException) {
			return NetWorkConstans.ERROR_IO_SSLException_SSLProtocolException;
		} else if (e instanceof BindException) {
			return NetWorkConstans.ERROR_IO_SocketException_BindException;
		} else if (e instanceof ConnectException) {
			return NetWorkConstans.ERROR_IO_SocketException_ConnectException;
		} else if (e instanceof NoRouteToHostException) {
			return NetWorkConstans.ERROR_IO_SocketException_NoRouteToHostException;
		} else if (e instanceof PortUnreachableException) {
			return NetWorkConstans.ERROR_IO_SocketException_PortUnreachableException;
		} else if (e instanceof SyncFailedException) {
			return NetWorkConstans.ERROR_IO_SyncFailedException;
		} else if (e instanceof UTFDataFormatException) {
			return NetWorkConstans.ERROR_IO_UTFDataFormatException;
		} else if (e instanceof UnknownHostException) {
			return NetWorkConstans.ERROR_IO_UnknownHostException;
		} else if (e instanceof UnknownServiceException) {
			return NetWorkConstans.ERROR_IO_UnknownServiceException;
		} else if (e instanceof UnsupportedEncodingException) {
			return NetWorkConstans.ERROR_IO_UnsupportedEncodingException;
		} else if (e instanceof ZipException) {
			return NetWorkConstans.ERROR_IO_ZipException;
		}
		return NetWorkConstans.ERROR_IO;
	}


}
